package com.hanggold.jfinal.demo.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-05-26 08:48
 * @since 1.0.0
 **/
public class ThreadLocalDemoTestMemory {
    private static final ThreadLocal<byte[]> local = new ThreadLocal<>();
    
    public static void main(String[] args) throws InterruptedException {
        
        List<byte[]> list = new ArrayList<>();
        
        for (int i = 0; i < 100; i++) {
            TimeUnit.SECONDS.sleep(4L);
            final int finalI = i;
            new Thread(() -> {
                byte[] bytes = new byte[1024 * 1024 * 20];
                //            list.add(bytes);
                try {
                    TimeUnit.SECONDS.sleep(3L);
                    
                    System.out.println("i: " + finalI + " ,当前线程： " + Thread.currentThread().getId());
                    local.set(bytes);
                    TimeUnit.MINUTES.sleep(60);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                
            }).start();
        }
        
    }
}
